//
//  WZMenuCell.m
//  ETong
//
//  Created by wanzhao on 15/12/8.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZMenuCell.h"

@interface WZMenuCell ()

@property (nonatomic, weak) UILabel *biaotiLabel;
@property (nonatomic, weak) UIView *shortLine;
@property (nonatomic, weak) UIView *upLongLine;
@property (nonatomic, weak) UIView *downLongLine;
@property (nonatomic, weak) UIView *rightLine;

@end

@implementation WZMenuCell

+ (WZMenuCell *)menuCellWithTableView:(UITableView *)tableView
{
    static NSString *menuCellId = @"menuCell";
    WZMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:menuCellId];
    if (cell == nil) {
        cell = [[WZMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:menuCellId];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = ClearColor;
        label.font = Font12;
        label.textAlignment = UITextAlignmentCenter;
        label.textColor = RGBCOLORWITH16COLOR(0x666666);
        [self.contentView addSubview:label];
        self.biaotiLabel = label;
        
        UIView *shortLine = [[UIView alloc] init];
        shortLine.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
        [self.contentView addSubview:shortLine];
        self.shortLine = shortLine;
        
        
        UIView *upLongLine = [[UIView alloc] init];
        upLongLine.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
        upLongLine.hidden = YES;
        [self.contentView addSubview:upLongLine];
        self.upLongLine = upLongLine;
        
        
        UIView *downLongLine = [[UIView alloc] init];
        downLongLine.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
        downLongLine.hidden = YES;
        [self.contentView addSubview:downLongLine];
        self.downLongLine = downLongLine;


        UIView *rightLine = [[UIView alloc] init];
        rightLine.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
        [self.contentView addSubview:rightLine];
        self.rightLine = rightLine;

    }
    return self;
}


- (void)setProcedure:(WZProcedure *)procedure
{
    _procedure = procedure;
    self.biaotiLabel.text = procedure.name;
    if (procedure.isSelected) {
        self.shortLine.hidden = YES;
        self.rightLine.hidden = YES;
        self.downLongLine.hidden = NO;
        self.upLongLine.hidden = NO;
    } else {
        self.shortLine.hidden = NO;
        self.rightLine.hidden = NO;
        self.downLongLine.hidden = YES;
        self.upLongLine.hidden = YES;
    }

}
//- (void)setMenuCellIsSelected:(BOOL)menuCellIsSelected
//{
//    _menuCellIsSelected = menuCellIsSelected;
//    if (_menuCellIsSelected) {
//        self.shortLine.hidden = YES;
//        self.rightLine.hidden = YES;
//        self.downLongLine.hidden = NO;
//        self.upLongLine.hidden = NO;
//    } else {
//        self.shortLine.hidden = NO;
//        self.rightLine.hidden = NO;
//        self.downLongLine.hidden = YES;
//        self.upLongLine.hidden = YES;
//    }
//}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.biaotiLabel.frame = CGRectMake(0, 0, self.width, self.height);
    self.rightLine.frame = CGRectMake(self.width - 0.5f, 0, 0.5f, self.height);
    self.shortLine.frame = CGRectMake(OppositeWidthRate(10), self.height - 0.5f, self.width - OppositeWidthRate(20), 0.5f);
    
    self.downLongLine.frame = CGRectMake(0, self.height - 0.5f, self.width, 0.5f);
    self.upLongLine.frame = CGRectMake(0, 0, self.width, 0.5f);
}

@end
